// __PUBLIC__/js/page/cms/template/addtpl
require(['../../common'], function() {
  require(['template.addtpl'])
})

define('template.addtpl', [
  'jquery',
  'jqp/validate'
], function($) {
  'use strict';
  var $form = $('#J_form')

  $(document).on('keydown', '#fieldname, #create_name', function() {
  	check()
  }).on('change', '#module', function() {
  	if ($(this).val() === 'home') {
  		$('#cn').show()
  	} else {
  		$('#cn').hide()
  	}
  }).ready(function() {
  	if ($('#module').val() === 'home') {
  		$('#cn').show()
  	}
  })

  function check() {
    var arr = [219, 221, 186, 222, 188, 190, 191];
    for (var m = 0; m < arr.length; m++) {
      if (window.event.keyCode == arr[m]) {
        window.event.returnValue = false;
      }
    }
  }

  $form.validate({
    classPlace: '.kv',
    errorPlace: '.kv-error',
    errors: {
      'fieldname': {
        required: '模版名称不能为空'
      },
      'templateContent': {
        required: '模版内容不能为空'
      }
    }
  })
})
